﻿package com.msjt.dao;

import java.util.List;

import com.msjt.base.BaseDAO;
import com.msjt.entity.Industry;
/**
 * name:IndustryDAO
 * function:主要行业数据处理
 * author: kw
 * time:2013.8.27
 */
public class IndustryDAO extends BaseDAO {
	//查看更多页面显示主营方向信息，每页20个主营方向信息
	@SuppressWarnings("unchecked")
	public List<Industry> getIndstryByPage(int pageSize,int pageIndex){
		String hql="select n from Industry as n";
		return (List<Industry>) this.searchByPage(hql, null, pageIndex, pageSize);
	}
	//主页面显示6个主业信息
	@SuppressWarnings("unchecked")
	public List<Industry> getIndexIndustry(){
		String hql="select new Industry(i.inId,i.inName,i.inPicPath) from Industry as i";
		return (List<Industry>) this.searchByPage(hql, null, 1, 6);
	}
	// 根据ID查询出主营行业的信息
	public Industry getIndustryById(Industry insdutry){
		return (Industry) this.findById(insdutry.getInId());
	}
	//添加主营方向信息
	public boolean addIndustry(Industry industry){
		return this.save(industry);
	}
	//修改主营方向信息
	public boolean updateIndustry(Industry industry){
		return this.saveOrUpdate(industry);
	}
	//删除主营方向的信息
	public boolean delteIndustry(Industry industry){
		return this.deleteById(industry.getInId());
	}
	//计算行业信息的总个数
	public Integer getIndustryCount(){
		String hql="select count(n.inId) from Industry as n";
		return this.getTotalCount(hql, null);
	}
	//批量删除时得到路径
		@SuppressWarnings("unchecked")
		public List<String> getIndustryPath(String idString){
			String hql="select industry.inPicPath from Industry as industry where industry.inId in ("+idString+")";
			return (List<String>) this.searchByHQL(hql, null);
		}
	/**
	 * 批量删除
	 * @param idString id的字符串，用“,”号隔开
	 * @return
	 */
	public boolean deleteMore(String idString){
		String hql="delete Industry as indus where indus.inId in ("+idString+")";
		return this.updateByHql(hql, null);
	}
}
